package com.qx.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import com.qx.dao.RolesDao;
import com.qx.entity.Roles;
import com.qx.service.RolesService;
@Service
public class RolesServiceimpl implements RolesService {
 
	@Autowired
	RolesDao rolesDao;

	@Override
	public Page<Roles> findRoles(Integer page, Integer limit) {
		if(page==null) page=1;
		if(limit==null) limit=10;
		Pageable r=PageRequest.of(page-1, limit);
		return rolesDao.findAll(r);
	}

	@Override
	public Integer save(Roles roles) {
		if(rolesDao.save(roles)!=null) {
			return 1;
		}else {
			return 0;
		}
	}

	@Override
	public Integer deleteRoles(Integer id) {
		try {
			rolesDao.deleteById(id);
			return 1;
		} catch (Exception e) {
			// TODO: handle exception
			return 0;
		}
	}

	@Override
	public Integer count() {
		// TODO Auto-generated method stub
		return (int)rolesDao.count();
	}

	@Override
	public List<Roles> getAll() {
		List<Roles>r=rolesDao.findAll();
		return r;
	}

	
	
}
